layui.use(['layedit','form','layer'], function(){
    var layer = layui.layer;
    var layedit = layui.layedit;
    var form=layui.form;
    layedit.build('demo', {
        height: 260 //设置编辑器高度
    });
    var $=layui.jquery
    $("#through").on('click',function(){
        layer.confirm("审核是否通过？", {
            btn: ["确定","取消"] //按钮
        }, function(index){
            var textarea=$("#textarea").val();//通过驳回原因
            var remarks=$("#remarks").val();//申请原因
            var applyDate=$("#applyDate").val();//申请日期
            var position=$("#position").val();//申请结果
            var launchId=$("#launchId").val();//申请人id
            audit(textarea,remarks,applyDate,position,launchId);
            layer.closeAll(index);
        }, function(){
        });
    })
    function audit(textarea,remarks,applyDate,position,launchId){
        var create=localStorage.getItem("user");
        create=JSON.parse(create);//转换为json
        var pass=create.userId;
        $.ajax({
            url:"/personnel/audit",//后台路径
            type:"post",
            dataType:"json",
            data:{"textarea":textarea,"remarks":remarks,"applyDate":applyDate,"position":position,"launchId":launchId,"pass":pass},
            success:function(data){
                var index = parent.layer.getFrameIndex(window.name);
                parent.location.reload();//刷新父页面
                parent.layer.close(index);//关闭当前页
            }
        })
    }

    $("#rejected").on('click',function(){
        layer.confirm("审核是否驳回", {
            btn: ["确定","取消"] //按钮
        }, function(index){
            var textarea=$("#textarea").val();//通过驳回原因
            var remarks=$("#remarks").val();//申请原因
            var applyDate=$("#applyDate").val();//申请日期
            var position=$("#position").val();//申请结果
            var launchId=$("#launchId").val();//申请人id
            rejected(textarea,remarks,applyDate,position,launchId);
            layer.close(index);
        }, function(){
        });
    })

    function rejected(textarea,remarks,applyDate,position,launchId){
        var create=localStorage.getItem("user");
        create=JSON.parse(create);//转换为json
        var pass=create.userId;

        $.ajax({
            url:"/personnel/rejected",//驳回后台路径
            type:"post",
            dataType:"json",
            data:{"textarea":textarea,"remarks":remarks,"applyDate":applyDate,"position":position,"launchId":launchId,"pass":pass},
            success:function(data){
                var index = parent.layer.getFrameIndex(window.name);
                parent.location.reload();//刷新父页面
                parent.layer.close(index);//关闭当前页
            }

        })
    }

});
